package com.tedu.api.d5_io_seri;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/*
 测试---编码转换流
 */
public class Test2_Encode {
    public static void main(String[] args) {
        OutputStreamWriter out=null;
        /*
         参数 "2.txt"不是磁盘路径，而是直接生成在项目下
         与src同级的文件
         */
        //创建流对象
        try {
            //out=new OutputStreamWriter(new FileOutputStream("2.txt"));
            //out=new OutputStreamWriter(new FileOutputStream("2.txt"),"iso-8859-1");
            out=new OutputStreamWriter(new FileOutputStream("2.txt"),"utf-8");

            out.write("齐天大圣!");
            System.out.println("输出成功");
        } catch (Exception e) {
            System.out.println("输出失败");
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
